#coding=utf-8
import time  
from selenium import webdriver  
import re

#driver = webdriver.Chrome(r'F:\Python\Economic\chromedriver_win32\chromedriver.exe')  #打开浏览器

def batch_check_stock_futures_FX_cybermoney(driver):
        
    
    elem = driver.get('https://cn.investing.com/indices/world-indices')  #打开网址
    information = "" #把结果要保存的变量先初始化好
    print('Stock markets are:\n')

    def get_info():   #定义主要方法： 复制利率到information变量，并同时打印出来
        nonlocal information #调用父方法的变量
        status = driver.page_source #把全网页源代码文本保存在status变量里
        rate = status[status.find('QBS_2_inner'):status.find('TechSummary')]
        filtered_service_log = re.findall("<td .*?>(.*?)<\/td>",rate) #把coding中间的部分去掉，只留下人类可读部分
        filtered_service_log1 = re.findall("<a .*?>(.*?)<\/a>",str(filtered_service_log))
        #print('The latest rate is: \n')
        for number in range(len(filtered_service_log)):
            if 'span' not in filtered_service_log[number] and '&nbsp;' not in filtered_service_log[number]:
                print(filtered_service_log[number] if re.findall("<a .*?>(.*?)<\/a>",filtered_service_log[number])==[] else re.findall("<a .*?>(.*?)<\/a>",str(filtered_service_log[number])))
                #information = information + filtered_service_log2[number][1] + ' '+ filtered_service_log1[number*2] + ' '
        #print('\n')  #前后空好行

    information = information + '\nBonds rates are:(ranked by GDP)'
    
    get_info()
    print('\n')

    div=driver.find_element_by_xpath('//h1[@class="float_lang_base_1 relativeAttr"]')
    js4 = "arguments[0].scrollIntoView();"
    driver.execute_script(js4, div)

    #print(information)  #根据需要打印出利率详情统计。

    #driver.quit()

#batch_check_stock_futures_FX_cybermoney(driver)
    

#batch_check_stock_futures_FX_cybermoney()


